<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "dh_sys_menu_Faq".
 *
 * @property integer $id
 * @property string $url
 * @property string $title
 * @property string $tips
 */
class SysMenuFaq extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'dh_sys_menu_faq';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['url', 'title'], 'string', 'max' => 256],
            [['tips'], 'string', 'max' => 100]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'url' => '路由地址(可以为空)',
            'title' => '常见问题内容',
            'tips' => '常见问题备注',
        ];
    }

    /**
     * @param $id
     * @destination: 常见问题的接口
     * @author:qiang.zuo
     * @auditor:jiangtao.ren
     * @date:2015-6-15 13:31:06
     */
    public static function getMenuId ($id){
        $sql = "select id,url,title,tips from dh_sys_menu_faq where id=".$id;
        $data = "";
        $info = [];
        $info = SysMenuFAQ::findBySql($sql)->asarray()->one();
        if($info){
            if(!empty($info['url'])){
                $data = "<a id='faq".$info['id']."' href='".$info['url']."' style='border-radius:8px;background-color:blue;color:white;text-decoration:none;padding:0 4px;text-align:center;font-weight:bold;margin:0 10px;' title='点击查看&nbsp;:&nbsp;&nbsp;".$info['tips']."' target='_blank'>?</a>";
            } else {
                $data = "<a id='faq".$info['id']."' href='javascript:void(0)' title='".$info['tips']."&nbsp;:&nbsp;&nbsp;".$info['title']."' style='border-radius:8px;background-color:blue;color:white;text-decoration:none;padding:0 4px;text-align:center;font-weight:bold;margin:0 10px;'>?</a>";
            }
        }else{
            $data = false;
        }

        return $data;
    }
}
